const {
	Service
} = require('uni-cloud-router')

module.exports = class GoodsCategoryService extends Service {
	async getCategories({
		rootCateName
	}) {
		try {
			var res = await this.db.collection('t3ds-mall-categories').where({
					name: rootCateName
				})
				.field({
					_id: true
				})
				.limit(1)
				.get()
			if (res.data.length) {
				res = await this.db.collection('t3ds-mall-categories').where({
					parentId: res.data[0]._id,
					enable: true
				})
				.get()
				return res.data
			}
			return []
		} catch (e) {
			throw e
		}
	}
}